package com.dididoctor.patient.Receive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.Activity.Login.loginActivity;
import com.dididoctor.patient.Bean.Token;
import com.dididoctor.patient.Utils.DataCleanManager;
import com.dididoctor.patient.Utils.LoaderImage;
import com.dididoctor.patient.Utils.MyToast;

/**
 * XMPP 退出登录广播
 *
 * @author nseer
 */
public class GoToLoginReceier extends BroadcastReceiver {
    private Context context;

    @Override
    public void onReceive(Context context, Intent intent) {
        this.context = context;
        String action = intent.getAction();
        if (action.equals(ConstantValue.goToLogin)) {
            String message = intent.getStringExtra("message");
            String msgType = intent.getStringExtra("msgType");
            if (ConstantValue.OGTOLOGINCODE.equals(msgType)) {
                intent = new Intent(context, loginActivity.class);
                intent.putExtra("isshowdialog", "show");
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                context.startActivity(intent);
                MyToast.DefaultmakeText(context, message, 1);
                DataCleanManager.cleanExternalCache(this.context);
                DataCleanManager.cleanInternalCache(this.context);
//                SharedPreferencesUtils.setParam(this.context, "READ", "0");
                LoaderImage.clearCache();
                Token.logout();
            }
        }

    }
}
